﻿using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using MedicWeb.forms;
using MedicWeb.MedicService;

namespace MedicWeb {
    public partial class Site1 : System.Web.UI.MasterPage {
        protected void Page_Load(object sender, EventArgs e) {
            string error = Session["error"] as string;

            Error.Visible = error != null;
            Error.Text = error;
            Session.Remove("error");

            string success = Session["success"] as string;
            Success.Visible = success != null;
            Success.Text = success;
            Session.Remove("success");

            string info = Session["info"] as string;
            Info.Visible = info != null;
            Info.Text = info;
            Session.Remove("info");

            bool login = Request.Url.LocalPath == ResolveUrl("~/Login.aspx");
            bool err = Request.Url.LocalPath == ResolveUrl("~/Error.aspx");
            if (!login && !err) {
                var ms = new MainService();
                Session session = (Session)Session[SessionPage.SessionKey];
                if (session != null) {
                    PublicUser user = ms.GetCurrentUser(session);
                    lblUser.Text = "Пользователь: " + user.Login;
                } else {
                    Session["error"] = "Необходима аутентификация";
                    Response.Redirect("~/Login.aspx");
                }
            }
            pnlUser.Visible = !login;
            /*
            var links = new String[] {
                                         "~/Style.css",
                                         "~/Styles/datepicker.css",
                                         "~/Styles/jquery-ui-1.8.13.custom.css",
                                     };
            foreach (var link in links) {
                HtmlGenericControl lnk = new HtmlGenericControl("link");
                lnk.Attributes["type"] = "text/css";
                lnk.Attributes["rel"] = "stylesheet";
                lnk.Attributes["href"] = ResolveUrl(link);
                Page.Header.Controls.Add(lnk);
            }

            var scripts = new String[] {
                                           "~/Scripts/jquery-1.6.min.js",
                                           "~/Scripts/jquery.columnfilters.js",
                                           "~/Scripts/ui.datepicker.js",
                                           "~/Scripts/MyScripts.js",
                                           "~/Scripts/jquery.form.js",
                                           "~/Scripts/scrollbarTable-0.1.min.js",
                                           "~/Scripts/jquery-ui-1.8.13.custom.min.js",
                                           "~/Scripts/jquery.floatbox.10.4.min.js",
                                           "~/Scripts/jquery.popup.js",
                                           
                                       };
            foreach (var script in scripts) {
                HtmlGenericControl js = new HtmlGenericControl("script");
                js.Attributes["type"] = "text/javascript";
                js.Attributes["src"] = ResolveUrl(script);
                Page.Header.Controls.Add(js);
            }
            */

            //string value = hfFilters.Value;
        }

        protected void btnExit_Click(object sender, EventArgs e) {
            Session.RemoveAll();
            Response.Redirect("~/Login.aspx");
        }
    }

}